package com.example.demo.mapper.sysuser;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;
import com.example.demo.bean.sysuser.SysUserDO;
import com.example.demo.mapper.BaseMapperX;
import com.example.demo.dto.sysuser.SysUserPageReqVO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 系统用户Mapper
 */
@Mapper
public interface SysUserMapper extends BaseMapperX<SysUserDO> {

    default PageRes<SysUserDO> selectPage(SysUserPageReqVO reqVO) {
        Page<SysUserDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        return selectPageCommon(page, new QueryWrapper<SysUserDO>()
                .like(ObjectUtil.isNotNull(reqVO.getUserName()), "user_name", reqVO.getUserName())
                .eq(ObjectUtil.isNotNull(reqVO.getStatus()), "status", reqVO.getStatus())
                .like(ObjectUtil.isNotNull(reqVO.getPhonenumber()), "phonenumber", reqVO.getPhonenumber())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "create_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
                .select("user_id","user_name","nick_name","phonenumber","status","create_time")
        );
    }

    default PageRes<SysUserDO> selectNotPage(SysUserPageReqVO reqVO) {
        return selectPageCommon(new QueryWrapper<SysUserDO>()
                .like(ObjectUtil.isNotNull(reqVO.getUserName()), "user_name", reqVO.getUserName())
                .eq(ObjectUtil.isNotNull(reqVO.getStatus()), "status", reqVO.getStatus())
                .like(ObjectUtil.isNotNull(reqVO.getPhonenumber()), "phonenumber", reqVO.getPhonenumber())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "create_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
                .select("user_id","user_name","nick_name","phonenumber","status","create_time")
        );
    }
}
